<?
    session_start(); //开启session
    $user=isset($_SESSION['user'])?$_SESSION['user']:false; //判断session是否存在
    // 读取博客列表
    // 连接数据库
    require_once $_SERVER['DOCUMENT_ROOT'].'/blog/lib/Db.php'; //绝对地址
    $db=new Db();
    // 博客分类
    $cates=$db->table('cates')->lists();

    // 分页获取内容
    $path='/blog/index.php';
    $page=isset($_GET['page'])?(int)$_GET['page']:1;
    $pageSize=2;
    $cid=isset($_GET['cid'])?(int)$_GET['cid']:0; //分类
    $where=[];
    if($cid){
        $where['cid']=$cid;
        $path.="?cid={$cid}";
    }
    $cntLists=$db->table('article')->field('id,title,pv,add_time')->order('id desc')->where($where)->pages( $page,$pageSize,$path);
    
    include_once './template/header.php';
    include_once './template/topnav.php';
?>
    <link rel="stylesheet" href="static/css/site.css">
    
    <!-- 内容区 -->
    <div class="main container">
        <?php include_once './template/classify.php'?>

        <div class="col-lg-10 col-md-10 col-sm-10">
            <div class="nav">
                <a href="" class="active">最新</a>
                <a href="">热门</a>
            </div>

            <ul class="content-list" style="padding-left:0;">
                <?php foreach($cntLists['data'] as $article){?>
                <li class="content-item">
                    <img src="static/img/avatar.png" alt="">
                    <div class="title">
                        <a href="/blog/detail.php?aid=<?php echo $article['id']?>"><?php echo $article['title']?></a>
                        <p><span><i class="glyphicon glyphicon-eye-open"></i> <?php echo $article['pv']?></span> <span><?php echo date('Y-m-d H:i:s',$article['add_time'])?></span></p>
                    </div>
                </li>
                <?php }?>
            </ul>
            <!-- 分页 -->
            <div> <?php echo $cntLists['pages']?></div>
        </div>
    </div>
<?php include_once './template/footer.php'?>
<script>
    $(function(){
        navActive();
    })
</script>